﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism;
using Sautom.ClientComunication;
using Sautom.ClientComunication.CommonService;
using Sautom.I18N;
using Sautom.Modules.EventNortification.Model;

namespace Sautom.Modules.EventNortification.Helpers
{
    internal class EventNotificationFormatter
    {
        private static readonly Dictionary<string, Func<EventNortificationOutput, EventNotificationItem>> Formatters
            = new Dictionary<string, Func<EventNortificationOutput, EventNotificationItem>>()
                  {
                      {"AirlineTicketBookingExpire", AirlineTicketBookingExpireFormatter}
                  };

        public static IEnumerable<EventNotificationItem> Process(IEnumerable<EventNortificationOutput> input)
        {
            return input.Select(notif => Formatters[notif.EventName](notif)).ToList();
        }

        #region Formatters
        private static EventNotificationItem AirlineTicketBookingExpireFormatter(EventNortificationOutput @event)
        {
            var uriQuery = new UriQuery
                               {
                                   {"clientId", @event.Args["ClientId"].ToString()}
                               };
            Uri uri = new Uri(PathProvider.ClientDetails + uriQuery, UriKind.Relative);
            
            string msg = string.Format(EventNotificationResources.AirlineTicketBookingExpireMessage,
                                       @event.Args["ClientName"].ToString(), ((DateTime)(@event.Args["ExpireDate"])).ToString("d"));
            
            return new EventNotificationItem(msg, EventType.Warning, uri);
        }
        #endregion
    }
}
